<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            margin: 10px auto;
        }
    </style>
</head>

<body>
    <div>
        <p id="num"></p>
    </div>
</body>

<script>

    var num = document.getElementById('num')

    var i = 0

    // 普通定时器, 会按设置的时间间隔持续触发 
    setInterval(sum, 1000)
    sum()

    function sum() {
        num.innerHTML = ++i
    }

</script>

</html>